import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/2/12.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class CustumOvalButton extends StatefulWidget {
  //图标
  final IconData iconData;

  final Color color;

  //点击事件回调
  final Function() clickCallBack;

  CustumOvalButton(
      {@required this.iconData, this.clickCallBack, Key key, this.color})
      : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _CustumOvalButtonState();
  }
}

class _CustumOvalButtonState extends State<CustumOvalButton>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation<double> _scalAnimation;

  @override
  void initState() {
    super.initState();
    _animationController = new AnimationController(
        vsync: this, duration: Duration(milliseconds: 100));
    _scalAnimation =
        Tween<double>(begin: 1.0, end: 1.2).animate(_animationController);
    _animationController.addStatusListener((status) {
      AnimationStatus animationStatus = _animationController.status;
      if (animationStatus == AnimationStatus.completed) {
        _animationController.reverse();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      //点击事件的响应范围
      borderRadius: BorderRadius.all(Radius.circular(30)),
      //点击事件
      onTap: () {
        widget.clickCallBack();
        _animationController.forward(from: 0);
      },
      child: ScaleTransition(
        scale: _scalAnimation,
        child: Container(
          width: 50,
          height: 30,
          //自定义边框
          decoration: BoxDecoration(
              //边框
              //border: Border.all(color:(widget.color?? Colors.grey[400])),
              //边框圆角
              borderRadius: BorderRadius.all(Radius.circular(30))),
          child: Icon(
            widget.iconData,
            //图标颜色
            color: widget.color ?? Colors.black54,
          ),
        ),
      ),
    );
  }
}
